import java.util.Stack;


public class RuleTupleFormation {

	Stack<ControlElement> control ;
	Stack<String> stack ;
	Environment environment;
	
	public RuleTupleFormation(Stack<ControlElement> control, Stack<String> stack, Environment environment){
		this.control = control;
		this.stack = stack;
		this.environment = environment;
	}
	
	public static void main(String[] args) {
		Stack<ControlElement> control = new Stack<ControlElement>();
		Stack<String> stack = new Stack<String>();
		Environment environment = new Environment();
		RuleTupleFormation ruleTupFrm = new RuleTupleFormation(control, stack, environment);

		// test1 
		control.push(new ControlTau("tau",2));
		stack.push("<INT:3>");
		stack.push("$$tau::2::<INT:2>::<INT:3>$$");
		stack.push("<INT:2>");
		System.out.println(ruleTupFrm.checkRule());
		//ruleOP.devide();
		//ruleOP.power();
		ruleTupFrm.applyRule();
		System.out.println("Control:"+ruleTupFrm.control + " Stack:" +ruleTupFrm.stack);
	}
	
	/*
	 * $$tau::#order::x::y::z::<INT:3>:<STR:'digi'>$$
	 */
	public void applyRule() {
		ControlTau controlTop = (ControlTau)control.pop();
		String returnValue = "$$tau::"+controlTop.order;
		for (int i = 0 ; i < controlTop.order ; i++){
			returnValue += "::" + stack.pop();
		}
		returnValue += "::$$";
		stack.push(returnValue);
	}

	public boolean checkRule() {
		if (control.peek() instanceof ControlTau)
			return true;
		else
			return false;
	}

}
